﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Linq;
using WRSManagementSystem.DomainModel.Entities;
using WRSManagementSystem.DomainModel.Repositories;

namespace WRSManagementSystem.Controllers
{
    public class UnitController : Controller
    {
        private readonly IUnitsRepository _unitsrepo;

        public UnitController(IUnitsRepository unitsrepo)
        {
            _unitsrepo = unitsrepo;
        }

        //
        // GET: /Unit/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Unit/Create

        public ActionResult Create()
        {
            return View(new Unit());
        }

        //
        // POST: /Unit/Create

        [HttpPost]
        public ActionResult Create(Unit model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add insert logic here
                    _unitsrepo.Add(model);
                    _unitsrepo.Save();
                    return RedirectToAction("Index", "StoreItem");
                }
                catch
                {
                    return View(model);
                }
            }
            return View(model);
        }

    }
}
